package com.hanbang.maige.pressenter.huodong;

import com.hanbang.maige.code.base.presenter.BasePresenter;
import com.hanbang.maige.mode.HttpRequest;
import com.hanbang.maige.mode.httpresponse.BaseHttpResponse;
import com.hanbang.maige.mode.httpresponse.HttpResult;
import com.hanbang.maige.mode.javabean.huodong.HuoDongItemData;
import com.hanbang.maige.utils.http.httpquest.HttpCallBack;
import com.hanbang.maige.utils.http.httpquest.HttpRequestParam;
import com.hanbang.maige.view.huodong.IHuoDongBaseView;

import java.util.List;

/**
 * 作者　　: 李坤
 * 创建时间:2016/9/19　17:05
 * 邮箱　　：496546144@qq.com
 * <p>
 * 功能介绍：
 */

public class HuoDongPresenter extends BasePresenter<IHuoDongBaseView.IHuoDongView> {


    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/26 14:33
     * <p>
     * 方法功能：首页-活动-更多	huodongMoreThan	pageIndex,pageSize
     */

    public void getHttpData(final boolean isStart) {
        if (isStart) {
            mvpView.clearPagingData();
        }
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setShowLoadding(false);
        buider.setSwipeRefreshLayout(mvpView.getSwipeRefreshLayout());
        buider.setLoadingAndRetryManager(mvpView.getLoadingAndRetryManager());
        HttpCallBack<HttpResult<List<HuoDongItemData>>> callBack = new HttpCallBack<HttpResult<List<HuoDongItemData>>>(buider) {
            @Override
            public void onSuccess(HttpResult<List<HuoDongItemData>> result) {
                super.onSuccess(result);

                if (result.isSucceed()) {
                    if (isStart) {
                        mvpView.clearData();
                    }

                    mvpView.updataUI((List<HuoDongItemData>) mvpView.getValidData(result.getData()));
                }
            }
        };

        HttpRequestParam param = new HttpRequestParam("huodongMoreThan");
        param.addPaging(mvpView.getPagingHelp());
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));

    }

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/26 14:33
     * <p>
     * 方法功能：活动报名	huodongBaoming	ActivityID：活动ID
     */

    public void postBaoming(String ActivityID, final int position) {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setHint("正在为您报名");
        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(BaseHttpResponse result) {
                super.onSuccess(result);
                if (result.isSucceed()) {
                    mvpView.baomingSuccess(result.getMsg(), position);
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }


            }
        };

        HttpRequestParam param = new HttpRequestParam("huodongBaoming");
        param.addParam("ActivityID", ActivityID);
        mvpView.addSubscription(HttpRequest.executeGet(callBack, param));
    }
}
